$(".but_submit").click(function () {
  var name = $.trim($("#userName").val());
  if (util.isBlank(name)) {
    $(".error_txt").text("姓名不能为空哦");
    $(".success").css("display", "none");
    $(".error").css("display", "block");
    layerOpen();
    return false;
  }

  var phone = $.trim($("#telephone").val());
  if (util.isBlank(phone)) {
    $(".error_txt").text("号码不能为空哦");
    $(".success").css("display", "none");
    $(".error").css("display", "block");
    layerOpen();
    return false;
  }

  var site = $.trim($("#address").val());
  var message = $.trim($("#message").val());

  $.ajax({
    type: "POST",
    url: "http://39.106.222.102:8889/publish/test",
    crossDomain: true,
    data: JSON.stringify({
     name: name,
	 phone: phone,
     site:site,
     message: message
    }),
    dataType: 'json',
    contentType: "application/json; charset=utf-8"
  }).done( function(res) {
    const {
     code: code,
     msg:msg
    } = res
    console.log(code);
    if (code === '100') {
      $(".success_txt").text(msg);
      $(".success").css("display", "block");
      $(".error").css("display", "none");
      layerOpen();
      $("#userName").val("");
      $("#telephone").val("");
      $("#address").val("");
      $("#message").val("");
    } else {
      $(".error_txt").text(msg);
      $(".success").css("display", "none");
      $(".error").css("display", "block");
      layerOpen();
    }
  }).fail(function(jqXHR, textStatus, errorThrown) {
    $(".error_txt").text(textStatus);
    $(".success").css("display", "none");
    $(".error").css("display", "block");
    layerOpen();
  })
});

function layerOpen() {
  layer.open({
    title: false,
    area: ['600px', '300px'],
    type: 1,
    shift: 4, //弹出方式
    closeBtn: 0, //不显示关闭按钮
    skin: 'popub_alt', //样式类名
    shadeClose: true, //开启遮罩关闭
    content: $('.popub_alt'),
    shade: [0.7, '#000'],
    icon: 5,
    btn: ['知道了'] //按钮
  });
};